<!DOCTYPE html>
<html>
	<head>
		<title>通知公告设置</title>
		<meta http-equiv="Pragma" CONTENT="no-cache">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="renderer" content="webkit">
		<link rel="stylesheet" type="text/css" href="${cxt!}/sb/css/setAnnounce.css">
		<%include("/common/include.html"){}%> 
		<style>
			table{
				width:100%;
				height:auto;
				background:#EFEFEF;
			}
			table tr{
				height:40px;
			}
		</style>
	</head>
	<body>
	
		<div class="easyui-layout" style="width:100%;height:100%;"  >
			<div data-options="region:'west'" style="width:220px">
				<div class="easyui-layout" style="width:100%;height:100%;">
					<div style="height:500px;width:100%">
						<div style="padding: 5px">
							<ul class="ztree" id="deptTree"></ul>
						</div>
					</div>			
				</div>
			</div>
			<form id="detailAnnounceForm"    method="post">
			<div data-options="region:'center'" style="overflow-x:hidden;">
				<div>
					<table border="0" >
						<tr>
							<td align="right" style="width:80px;">标题:</td>
							<td align="left">
								<input id="title" class="easyui-textbox theme-textbox-radius" style="width:85%;height:32px" name="detailAnnounce.title">
							</td>
						</tr>
						<tr>
							<td align="right" style="width:80px;">发送人:</td>
							<td align="left">
								<input class="easyui-textbox theme-textbox-radius" style="width:85%;height:30px;" value="${curUser.name! }" readonly="readonly">
								<input type="hidden" value="${curUser.ids! }" name="senderIds">
							</td>
						</tr>
						<input  type="hidden"  name="detailAnnounce.organizationIds" id="shoujianId"/>
						<input  type="hidden"  name="detailAnnounce.organizationName" id="shoujianname"/>
						<!-- <tr>
							<td align="right" style="width:80px;">时间:</td>
							<td align="left">
								<input class="easyui-datebox theme-textbox-radius" style="width:85%;height:30px;" value='${date(),dateFormat="yyyy-MM-dd"}'>
							</td>
						</tr> -->
						<!-- <tr>
							<td align="right" style="width:80px;">收件人:</td>
							<td align="left">
								<ul class="check">
									<%for(level in levels){%>
										<li style="margin-left:0px;">
											<input    type="checkbox" class="check_view_state" id="checkbox-${levelLP.index}"   style="display: none;" >
											<label for="checkbox-${levelLP.index}"></label>
											<span class="status">${level.name!} </span>
										</li>
									<%}%>
								</ul>
							</td>
						</tr> -->
					</table>
					<div style="text-align:content;margin-top:10px;width:92%;margin-left: 7%">
					<input  id="message" name="detailAnnounce.message" class="easyui-textbox" data-options="multiline:true" style="width:86%;height:250px;">
					</div>
					<div style="text-align:content;margin-top:10px;width:95%;margin-left: 45%">
						<a href="#"   class="easyui-linkbutton" data-options="iconCls:'icon-ok'"  onclick="submitForm()"  style="width:80px">发送</a>
					</div>
				</div>
				</div>
				</form>
			</div>
			<script type="text/javascript">
			var submitNow=function($dialog, $grid, $tree, $pjq){
				var treeObj=$.fn.zTree.getZTreeObj("deptTree");
			 	var nodes=treeObj.getCheckedNodes(true);
			 	if(nodes.length<1){
			 		 alert("发送人不能为空!");
					return false;
			 	}
	            var str="";
	            var strid="";
	            for(var i=0;i<nodes.length;i++){
	            	str+=nodes[i].name + ",";
	            	strid+=nodes[i].id + ",";
	            }
	            str=str.substring(0,str.length-1);
	            strid=strid.substring(0,strid.length-1);
	            $("#shoujianname").val(str);
	            $("#shoujianId").val(strid);
	            
	            var title =$("#title").val();
	            var message =$("#message").val();
	            if(title == null||title.length<1){
	            	alert("标题不能为空!");
	        		return false;
	        	}
	        	if(message == null||message.length<1){
	        		 alert("内容不能为空!");
	        		return false;
	        	}
	            
				var url = "${cxt !}/detailAnnounce/saveDetailAnnounce";
				$.post(url, sy.serializeObject($('#detailAnnounceForm')),function(result){
					if(result == true){
						$.slideMsg("发送成功！", $pjq);	
					}else{
						$.slideMsg("发送失败！", $pjq);	
					}
				},'json'); 
				
			} 
			var submitForm = function($dialog, $grid, $tree, $pjq) {
				submitNow($dialog, $grid, $tree, $pjq);
			}
			
			
			
			</script>
			
			
		<script type="text/javascript">
		//@ sourceURL=ogarntree.js
	
		/*var checkbox_1=document.getElementById("checkbox-1");
		var checkbox_2=document.getElementById("checkbox-2");
		var checkbox_3=document.getElementById("checkbox-3");
		var checkbox_4=document.getElementById("checkbox-4");
		checkbox_1.onclick = function(){
			var zTree = $.fn.zTree.getZTreeObj("deptTree");
			if(this.checked){
				zTree.checkAllNodes(true);
				checkbox_2.checked=true;
				checkbox_3.checked=true;
				checkbox_4.checked=true;
			}else{
				zTree.checkAllNodes(false);
				checkbox_2.checked=false;
				checkbox_3.checked=false;
				checkbox_4.checked=false;
			}
			
		}	 
		 checkbox_2.onclick=function(){
			var checked = this.checked;
			var zTree = $.fn.zTree.getZTreeObj("deptTree");
			var nodes = zTree.getNodesByParam("levelNum", "3", null);
			for(var i=0; i < nodes.length; i++){
				if(checked){
					zTree.checkNode(nodes[i], true, false);
				}else{
					zTree.checkNode(nodes[i], false, false);
					checkbox_1.checked=false;
				}
				
			}
		} 
	 	checkbox_3.onclick=function(){
			var checked = this.checked;
			var zTree = $.fn.zTree.getZTreeObj("deptTree");
			var nodes = zTree.getNodesByParam("levelNum", "4", null);
			for(var i=0; i < nodes.length; i++){
				if(checked){
					zTree.checkNode(nodes[i], true, false);
				}else{
					zTree.checkNode(nodes[i], false, false);
					checkbox_1.checked=false;
				}
				
			}
		} */
		
		//////////////////初始化////////////////////
		
		$(document).ready(function() {
			 $.fn.zTree.init($("#deptTree"), setting);
		});
		
		
		
		var setting = {
			async : {
				enable : true,
				url : '${cxt!}/organization/treeData',
				autoParam : [ "id=ids" ],//, "name=n", "level=lv"
				//otherParam : {"otherParam" : "zTreeAsyncTest"},
				type : "post"
			},
			data : {
				simpleData : {
					enable : true
				}
			},
			callback : {
				onCheck : deptTreeOnClick,
				beforeExpand : beforeExpand,
				//onExpand : onExpand,
				onAsyncSuccess : organTreeOnAsyncSuccess
			},
			check: {
				enable: true,
				chkStyle: "checkbox",
				//chkboxType: { "Y": "ps", "N": "ps" },
				chkboxType: { "Y": "", "N": "" },
			}
		};
		function deptTreeOnClick(event, treeId, treeNode,level) {
			var treeObj = $.fn.zTree.getZTreeObj("deptTree");	
			var allNodes=treeObj.transformToArray(treeObj.getNodes());
			var checkedNodes = treeObj.getCheckedNodes(true);
			var rootNode = treeObj.getNodesByParam("level", 0, null)[0];
			var	level = treeObj.getNodesByParam("name", "总部", null)[0].level;
			var agentNodes=treeObj.getNodesByParam("level", level+2, null);
			var fontStoreNodes=treeObj.getNodesByParam("level", level+3, null);
			var checkedStoreNum=0;
			var checkedAgentNum=0;
			//门店
			 for(var i=0;i<fontStoreNodes.length;i++){
				var fontStoreNodesHalfCheck=fontStoreNodes[i].getCheckStatus();
				if(fontStoreNodes[i].checked==true && fontStoreNodesHalfCheck.half==false){
					checkedStoreNum++;				
				}
			} 
			
			//代理
			for(var i=0;i<agentNodes.length;i++){
				var agentNodesHalfCheck=agentNodes[i].getCheckStatus();
				if(agentNodes[i].checked==true){
					checkedAgentNum++;
				}
			} 
			
			//全部
			var all=0;
			for(var i=0;i<allNodes.length;i++){
				if(allNodes[i].checked==true && allNodes[i].getCheckStatus().half==false){
					all++;
				}
				
			}
			
			
			
		}

		var firstAsyncSuccessFlag = 0;
		function organTreeOnAsyncSuccess(event, treeId, msg) {
			if (firstAsyncSuccessFlag == 0) {
				try {
					var deptTree = $.fn.zTree.getZTreeObj("deptTree");
					
					
					//deptTree.expandAll(true);
					 
					//调用默认展开第一个结点  
					var nodes = deptTree.getNodes();
					deptTree.expandNode(nodes[0], true);
					deptTree.selectNode(nodes[0]);  
					
	
					var childNodes = organTree.transformToArray(nodes[0]);
					organTree.expandNode(childNodes[1], true);
					firstAsyncSuccessFlag = 1;
				} catch (err) {
	
				}
	
			}
		} 
	
		////////////////////下面是处理展开//////////////////
	
		var curExpandNode = null;
		function beforeExpand(treeId, treeNode) {
			var pNode = curExpandNode ? curExpandNode.getParentNode() : null;
			var treeNodeP = treeNode.parentTId ? treeNode.getParentNode() : null;
			var zTree = $.fn.zTree.getZTreeObj("deptTree");
			for (var i = 0, l = !treeNodeP ? 0 : treeNodeP.children.length; i < l; i++) {
				if (treeNode !== treeNodeP.children[i]) {
					zTree.expandNode(treeNodeP.children[i], false);
				}
			}
			while (pNode) {
				if (pNode === treeNode) {
					break;
				}
				pNode = pNode.getParentNode();
			}
			if (!pNode) {
				singlePath(treeNode);
			}
	
		}
		function singlePath(newNode) {
			if (newNode === curExpandNode)
				return;
	
			var zTree = $.fn.zTree.getZTreeObj("deptTree"), rootNodes, tmpRoot, tmpTId, i, j, n;
	
			if (!curExpandNode) {
				tmpRoot = newNode;
				while (tmpRoot) {
					tmpTId = tmpRoot.tId;
					tmpRoot = tmpRoot.getParentNode();
				}
				rootNodes = zTree.getNodes();
				for (i = 0, j = rootNodes.length; i < j; i++) {
					n = rootNodes[i];
					if (n.tId != tmpTId) {
						zTree.expandNode(n, false);
					}
				}
			} else if (curExpandNode && curExpandNode.open) {
				if (newNode.parentTId === curExpandNode.parentTId) {
					zTree.expandNode(curExpandNode, false);
				} else {
					var newParents = [];
					while (newNode) {
						newNode = newNode.getParentNode();
						if (newNode === curExpandNode) {
							newParents = null;
							break;
						} else if (newNode) {
							newParents.push(newNode);
						}
					}
					if (newParents != null) {
						var oldNode = curExpandNode;
						var oldParents = [];
						while (oldNode) {
							oldNode = oldNode.getParentNode();
							if (oldNode) {
								oldParents.push(oldNode);
							}
						}
						if (newParents.length > 0) {
							zTree.expandNode(oldParents[Math.abs(oldParents.length
									- newParents.length) - 1], false);
						} else {
							zTree.expandNode(oldParents[oldParents.length - 1],
									false);
						}
					}
				}
			}
			curExpandNode = newNode;
		}
	
		
	</script>
	</body>
</html>